package com.imay.live.activity;

import android.os.Bundle;

import com.imay.cocos.IMayCocos;
import com.imay.live.analytics.MobclickAgent;

/**
 * Created by Administrator on 2017/8/22 0022.
 */

public abstract class BaseUpdateActivtiy extends BaseMainUiActivity {

    boolean canstart = false;//这是广告倒计时是否到 别改动 影响升级弹窗
    boolean cosstart = false;//这是cocos 升级 别改动 影响升级弹窗

    protected IMayCocos.OnCocosUpdateListener onCocosUpdateListener;
    protected boolean cocosViewShowing;

    public abstract void cocosUpdateSuccess();

    /**
     * 检查cocos
     */
    protected void checkUpdateCocos() {
        if (onCocosUpdateListener != null) {//防止建楼卡
            IMayCocos.getInstance().removeOnCocosUpdateListener(onCocosUpdateListener);
        }
        onCocosUpdateListener = new IMayCocos.OnCocosUpdateListener() {
            @Override
            public void onCocosAllowAction(int state) {
                if (state == 3) {
                    cosstart = false;
                    cocosUpdateSuccess();
                } else if (state == 2 || state == 1) {
                    cosstart = true;
                }
            }
        };
        IMayCocos.getInstance().addOnCocosUpdateListener(onCocosUpdateListener);
    }

    /**
     * cocos是否更新中
     *
     * @return
     */
    protected boolean isCocosUpdate() {
        return cosstart;
    }

    /**
     * cocos是否在显示
     *
     * @return
     */
    protected boolean isCocosViewShowing() {
        return cocosViewShowing;
    }

    protected void bringCocosViewToFront() {
        if (fl_cocos_view_container != null) {
            if (fl_cocos_view_container.getChildCount() == 0) {
                addCocosView(fl_cocos_view_container);
            }
            fl_main.bringChildToFront(fl_cocos_view_container);
            fl_main.updateViewLayout(fl_cocos_view_container, fl_cocos_view_container.getLayoutParams());
            cocosViewShowing = true;
        }
    }

    protected void revertCocosView() {
        fl_main.bringChildToFront(container);
        fl_main.updateViewLayout(container, container.getLayoutParams());
        cocosViewShowing = false;
        IMayCocos.getInstance().removeOnCocosUpdateListener(onCocosUpdateListener);
        onCocosUpdateListener = null;
    }

}
